package com.zhenghaijin.favoritesservice.mapper;

import com.zhenghaijin.favoritesservice.model.Favorite;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface FavoriteMapper {
    
    @Select("SELECT * FROM favorites WHERE user_id = #{userId}")
    List<Favorite> findByUserId(Long userId);

    @Select("SELECT * FROM favorites WHERE user_id = #{userId} AND anime_id = #{animeId}")
    Favorite findByUserIdAndAnimeId(@Param("userId") Long userId, @Param("animeId") Long animeId);

    @Insert("INSERT INTO favorites(user_id, anime_id, created_at) VALUES (#{userId}, #{animeId}, #{createdAt})")
    int insert(Favorite favorite);

    @Delete("DELETE FROM favorites WHERE user_id = #{userId} AND anime_id = #{animeId}")
    int deleteByUserIdAndAnimeId(@Param("userId") Long userId, @Param("animeId") Long animeId);
}